package com.bw.module_service.ui

import android.annotation.SuppressLint
import android.content.Intent
import android.os.Build
import android.os.Bundle
import android.widget.PopupMenu
import androidx.activity.enableEdgeToEdge
import androidx.activity.viewModels
import androidx.annotation.RequiresApi
import androidx.appcompat.app.AppCompatActivity
import androidx.core.view.ViewCompat
import androidx.core.view.WindowInsetsCompat
import androidx.databinding.DataBindingUtil.setContentView
import com.alibaba.android.arouter.facade.annotation.Route
import com.bw.lib_common.arouter.Router
import com.bw.lib_common.arouter.Router.Ui.LoginActivity
import com.bw.lib_common.base.BaseActivity
import com.bw.lib_storage.mmkv.AuthMMKV
import com.bw.module_service.R
import com.bw.module_service.adapter.FragmentAdapter
import com.bw.module_service.adapter.FragmentAdapter2
import com.bw.module_service.databinding.ActivityMonthVipBinding
import com.bw.module_service.viewmodel.ServiceViewModel
import com.tencent.mmkv.MMKV
import dagger.hilt.android.AndroidEntryPoint
import java.time.LocalDate
import java.time.format.DateTimeFormatter

@AndroidEntryPoint
@Route(path = Router.Ui.MonthVipActivity)
class MonthVipActivity : BaseActivity<ServiceViewModel, ActivityMonthVipBinding>() {
    override val mLayoutResId: Int
        get() = R.layout.activity_month_vip
    private val mViewModel: ServiceViewModel by viewModels()


    override fun initView() {

        val tabTitles = arrayOf("黄金会员", "铂金会员", "钻石会员")
        var adapter = FragmentAdapter2(supportFragmentManager, tabTitles)
        mBinding.viewPager.adapter = adapter
        mBinding.tabLayout.setupWithViewPager(mBinding.viewPager)
        mBinding.back.setOnClickListener {
            finish()
        }
        mBinding.add.setOnClickListener { v ->
            val popupMenu = PopupMenu(this, v)
            popupMenu.menuInflater.inflate(R.menu.vip_menu, popupMenu.menu)
            popupMenu.setOnMenuItemClickListener { item ->
                when (item.itemId) {
                    R.id.add_vip -> {
                        val intent = Intent(this, AddVipActivity::class.java)
                        startActivity(intent)
                    }
                }
                true
            }
            popupMenu.show()
        }
    }

    override fun initData() {
        mViewModel.getVipByUserId(AuthMMKV.userid)
    }



    override fun initListener() {
        super.initListener()
        mViewModel.vipLiveData_.observe(this) {
            mBinding.mViewModel = mViewModel
        }
    }


    override fun onResume() {
        super.onResume()

        mViewModel.getVipByUserId(AuthMMKV.userid)

    }


}